package com.cet.algorithm.贪心算法.买卖股票最佳时机;

/**
 * @program: cet-practice
 * @description: 买卖股票最佳时机2
 * @author: 陈恩涛
 * @create: 2023-06-07 22:53
 **/
public class LC122 {

    /**
     * 每一次上升都掌握住
     * @param prices
     * @return
     */
    public int maxProfit(int[] prices) {
        int result = 0;

        for (int i = 0; i < prices.length; i++) {
            if (i == 0) {
                continue;
            }

            int amplify = prices[i] - prices[i - 1];

            if (amplify > 0) {
                result += amplify;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        LC122 lc122 = new LC122();
        System.out.println(lc122.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
